package com.xcjh.opencv.rule;

import cn.hutool.extra.spring.SpringUtil;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.Map;
import java.util.Objects;

@Service
public class BaseStrategy {

    private static Map<String,BaseRule> map=null;
    private synchronized void init(){
        map = SpringUtil.getApplicationContext().getBeansOfType(BaseRule.class);
    }

    public void checkRun(String rule, Robot robot) throws Exception {
        //找到所有的实现类
        if(map==null){
            init();
        }
        for (BaseRule value : map.values()) {
            //命中对应的规则
            if(Objects.equals(rule,value.getRuleName())){
                //就执行
                value.run(robot);
                break;
            }
        }
    }


}
